package com.lhys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lhys.mapper.AssetProviderTypeMapper;
import com.lhys.pojo.AssetProviderType;
import com.lhys.service.AssetProviderTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 资产_供应商_类型表 服务实现类
 * </p>
 *
 * @author 小七
 * @since 2021-05-06
 */
@Service
public class AssetProviderTypeServiceImpl implements AssetProviderTypeService {
    @Autowired
    private AssetProviderTypeMapper assetProviderTypeMapper;

    @Override
    @Transactional
    public Boolean saveAssetProviderType(AssetProviderType assetProviderType) {
        try {
            if (assetProviderType.getId() == null) {
                return assetProviderTypeMapper.addAssetProviderType(assetProviderType) > 0;
            }
            return assetProviderTypeMapper.updateAssetProviderType(assetProviderType) > 0;
        } catch (Exception e) {
            System.out.println("重复添加");
            return null;
        }
    }

    @Override
    @Transactional
    public Boolean delAssetProviderTypeById(Integer id) {
        return assetProviderTypeMapper.delAssetProviderTypeById(id) > 0;
    }

    @Override
    public Boolean delAssetProviderTypeByTitle(String title) {
        return assetProviderTypeMapper.delAssetProviderTypeByTitle(title) > 0;
    }

    @Override
    public AssetProviderType getAssetProviderTypeById(Integer id) {
        return assetProviderTypeMapper.getAssetProviderTypeById(id);
    }

    @Override
    public AssetProviderType getAssetProviderTypeByTitle(String title) {
        return assetProviderTypeMapper.getAssetProviderTypeByTitle(title);
    }

    @Override
    public List<AssetProviderType> getAssetProviderTypeList() {
        return assetProviderTypeMapper.getAssetProviderTypeList();
    }

    @Override
    public PageInfo<AssetProviderType> getAssetProviderTypeList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AssetProviderType> list = assetProviderTypeMapper.getAssetProviderTypeList();
        PageInfo<AssetProviderType> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
